<template>
  <!-- 我申报的金融产品 -->
  <div class="layout">
    <ContainerTitle text="资金使用登记"></ContainerTitle>
    <div class="msgDiv">
      <el-table
        :data="capitalRegister"
        style="width: 100%"
        min-height="400"
        :border="true"
        :header-cell-style="{ background: '#F4F4F4', color: '#045DB9' }"
      >
        <el-table-column prop="capitalMatters" label="政策名称">
        </el-table-column>
        <el-table-column prop="declaredAmount" label="申报金额" width="120">
          <template slot-scope="scope">
            <span>{{
              scope.row.declaredAmount
                ? scope.row.declaredAmount / 10000 + "万"
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="applyTime" label="申请时间" width="200">
        </el-table-column>

        <el-table-column label="兑现状态" width="120" :resizable="false">
          <template slot-scope="scope">
            <span
              :style="
                'color: ' +
                formatApplyStatus(scope.row.redemptionStatus).color
              "
              >{{
                formatApplyStatus(scope.row.redemptionStatus).label
              }}</span
            >
          </template>
        </el-table-column>

        <el-table-column label="操作" width="80">
          <template slot-scope="scope">
            <span class="rowBtn" @click="toDetail(scope.row)">查看</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20, 25, 30, 35, 40, 45]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { registrationList } from "@/common/api/company.js";
export default {
  data() {
    return {
      name: "finance",
      currentPage: 1,
      pageSize: 10,
      total: 0,
      crumbs: [
        {
          label: "企业空间",
          value: "company",
        },
        {
          label: "金融服务",
          value: "finance",
        },
        {
          label: "资金使用登记",
          value: "capitalRegister",
          choose: true,
        }
      ],
      capitalRegister: [],

      applyStatusList: [
        { value: 1, label: "待审核" },
        { value: 2, label: "审核中" },
        { value: 3, label: "已兑现" },
        { value: 4, label: "失败" },
        { value: 5, label: "已过期 " },
      ],
    };
  },

  mounted() {
    this.getList();
  },
  methods: {
    //
    async getList() {
      let res = await registrationList({ pageNum: this.currentPage, pageSize: this.pageSize });
      if (res.code == 200) {
        this.capitalRegister = res.rows;
        this.total = res.total;
        // 格式化时间
        this.capitalRegister.forEach((el) => {
          el.applyTime = new Date(el.applyTime).pattern("yyyy-MM-dd");
        });
      }
    },
    // 兑现状态
    formatApplyStatus: function (redemptionStatus) {
      let ns = this;
      for (let i = 0; i < ns.applyStatusList.length; i++) {
        if (redemptionStatus == ns.applyStatusList[i].value) {
          return ns.applyStatusList[i];
        }
      }
      return { label: "" };
    },
    // 去详情
    toDetail(row) {
      localStorage.setItem("capitalId", row.id);
      localStorage.setItem("capitalMatters", row.capitalMatters);
      localStorage.setItem("declaredAmount", row.declaredAmount);
      console.log('enterpriseId', row)
      this.$router.push({
        name: "capitalRegisterList",
        query: { capitalId: row.id },
      });
    },

    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
    },
  },
};
</script>
<style scoped>
.breadcrumb {
  width: 1000px;
  margin: 20px 0;
}

.roomDiv {
  display: flex;
  justify-content: center;
}

.roomDiv .leftDiv {
  width: 200px;
  text-align: left;
}

.roomDiv .rightDiv {
  width: 800px;
  margin-left: 30px;
}
.titleDiv {
  border-bottom: 2px solid #045db9;
  text-align: left;
  padding: 10px;
  font-size: 20px;
  font-weight: bold;
  color: #045db9;
  margin-bottom: 20px;
}

.layout {
  min-height: 100vh;
  position: relative;
  padding-bottom: 150px;
  box-sizing: border-box;
}
.msgDiv {
  margin: 40px 0;
}
.rowBtn {
  cursor: pointer;
  margin-right: 12px;
}

.block {
  margin-top: 14px;
  text-align: right;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}
.rowBtn {
  cursor: pointer;
}
</style>